package com.lanou.pianke.search.service.impl;


import com.lanou.pianke.search.EntityRepository.AreplyRepository;
import com.lanou.pianke.search.entity.Areply;
import com.lanou.pianke.search.service.AreplyService;
import org.elasticsearch.index.query.QueryStringQueryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


@Service
public class AreplyServiceImpl implements AreplyService {

    @Autowired
    private AreplyRepository areplyRepository;

    @Override
    public List<Areply> searchByAreplyContent(String searchContent) {
        QueryStringQueryBuilder builder = new QueryStringQueryBuilder(searchContent);
        Iterable<Areply> searchResult = areplyRepository.search(builder);
        Iterator<Areply> areplyIterator = searchResult.iterator();
        List<Areply> areplyList = new ArrayList<>();
        while (areplyIterator.hasNext()){
            areplyList.add(areplyIterator.next());
        }
        return areplyList;
    }
}
